var idcardBase64="";
var busBase64="";
$(function(){  	    
  $('.input-file2').on('touchend',function() {
     uploadImg($('.input-file2'),$('.uploader-file2'),1)
    })
    $('.input-file1').on('touchend',function() {
     uploadImg($('.input-file1'),$('.uploader-file1'),2)
    })
  function  uploadImg(a,b,c) {

    var $uploader = a;
    var $ulWrap = b;
    var $gallery = $("#gallery"), $galleryImg = $("#galleryImg");
    // 允许上传的图片类型  
    var allowTypes = ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'];  
    // 10*1024KB，也就是 10MB  
    var maxSize = 10 * 1024 * 1024;
    // 图片最大宽度  
    var maxWidth = 500;
    // 最大上传图片数量  
    var maxCount = 1;
    $uploader.on('change', function (event) {
      console.log("第二次")
      var files = event.target.files;
        console.log($uploader)
        // 如果没有选中文件，直接返回  
        if (files.length === 0) {  
          return;  
        }  
        for (var i = 0, len = files.length; i < len; i++) {  
          var file = files[i];  
          var reader = new FileReader();
          
            // 如果类型不在允许的类型范围内  
            if (allowTypes.indexOf(file.type) === -1) {    
              continue;  
            }  
            
            if (file.size > maxSize) {   
              $("#iosDialog2").css("display","block")
              return;  
            }             
            reader.onload = function (e) {  
              var img = new Image();  
              img.onload = function () {  
                    // 不要超出最大宽度  
                    var w = Math.min(maxWidth, img.width);  
                    // 高度按比例计算  
                    var h = img.height * (w / img.width);  
                    var canvas = document.createElement('canvas');  
                    var ctx = canvas.getContext('2d');  
                    // 设置 canvas 的宽度和高度  
                    canvas.width = w;  
                    canvas.height = h;  
                    ctx.drawImage(img, 0, 0, w, h);  
                    var base64 = canvas.toDataURL('image/png');  
                    if(c==1){
                    	busBase64=base64.substr(base64.indexOf(",")+1);
                    }else{
                    	idcardBase64=base64.substr(base64.indexOf(",")+1);
                    }
                    // 插入到预览区  
                    var $preview = $('<li class="weui-uploader__file weui-uploader__file_status" style="background-image:url(' + base64 + ')"><div class="weui-uploader__file-content">0%</div></li>'); 
                    $ulWrap.children().remove(); 
                    $ulWrap.next().addClass("change") 
                    $ulWrap.append($preview); 
                    // $ulWrap.next().remove();  
                    
                    // 然后假装在上传，可以post base64格式，也可以构造blob对象上传，也可以用微信JSSDK上传  
                    var progress = 0;  
                    function uploading() {  
                      $preview.find('.weui-uploader__file-content').text(++progress + '%');  
                      if (progress < 100) {  
                        setTimeout(uploading, 1);  
                      }else {  
                            // 如果是失败，塞一个失败图标  
                            //$preview.find('.weui_uploader_status_content').html('<i class="weui_icon_warn"></i>');  
                            $preview.removeClass('weui-uploader__file_status').find('.weui-uploader__file-content').remove();  
                        }  
                    }  
                    setTimeout(uploading, 1);  
                };  
                      
                img.src = e.target.result;  
            };  
            reader.readAsDataURL(file);  
        } 
    }) 
  }

//# sourceURL=pen.js  


});